using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using Intelsi.Entity;

namespace Intelsi.DataAccess.Mapping
{
    public class BancoProvedorMap : EntityTypeConfiguration<BancoProvedor>
    {
        public BancoProvedorMap()
        {
            // Primary Key
            this.HasKey(t => new { t.IdProveedor, t.IdBanco });

            // Properties
            this.Property(t => t.IdProveedor)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.IdBanco)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.TipoPago)
                .IsRequired()
                .HasMaxLength(8);

            this.Property(t => t.NumeroCuenta)
                .HasMaxLength(20);

            this.Property(t => t.TipodeCuenta)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(1);

            // Table & Column Mappings
            this.ToTable("BancoProvedor");
            this.Property(t => t.IdProveedor).HasColumnName("IdProveedor");
            this.Property(t => t.IdBanco).HasColumnName("IdBanco");
            this.Property(t => t.TipoPago).HasColumnName("TipoPago");
            this.Property(t => t.LineaCredito).HasColumnName("LineaCredito");
            this.Property(t => t.NumeroCuenta).HasColumnName("NumeroCuenta");
            this.Property(t => t.TipodeCuenta).HasColumnName("TipodeCuenta");

            // Relationships
            this.HasRequired(t => t.Banco)
                .WithMany(t => t.BancoProvedors)
                .HasForeignKey(d => d.IdBanco);
            this.HasRequired(t => t.Proveedor)
                .WithMany(t => t.BancoProvedors)
                .HasForeignKey(d => d.IdProveedor);

        }
    }
}
